package de.tabuma.path;

import java.util.*;
import java.io.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.2.1 $
 * @since $Date: 2010/01/04 10:35:02 $
 */
public class path {

    public static String getContext(String path) {

        String content = "";

        try {
            FileReader fr = new FileReader(path);
            BufferedReader br = new BufferedReader(fr);
            String s;
            while((s = br.readLine()) != null) {
                content = content + s + "\n";
            }
            fr.close();
        }
        catch(Exception e) {
            e.printStackTrace();
        }

        return content;

    }

    public static Vector<String> getFilePath(String path) {
        return getFilePath(path,"");
    }

    public static Vector<String> getFilePath(String path,String end) {
        Vector<String> filePathList = new Vector<String>();
        File myFile = new File(path);
        if(myFile.isDirectory()) {
            File[] subFileList = myFile.listFiles();
            if(subFileList!=null) {
                for(int i=0;i<subFileList.length;i++) {
                    String newPath = subFileList[i].getPath();
                    Vector<String> zwischenErgebnis = getFilePath(newPath,end);
                    filePathList.addAll(zwischenErgebnis);
                }
            }
        }
        else {
            if(path.endsWith(end)) {
                filePathList.addElement(path);
            }
            else {
                if(end.equals("")) {
                    filePathList.addElement(path);
                }
            }
        }
        return filePathList;
    }
}
